package net.siufung.simple.config.mybatis;

import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import net.siufung.mybatis.metaobject.AbstractMybatisMetaObjectService;
import net.siufung.mybatis.metaobject.MybatisMetaObjectService;
import net.siufung.security.api.AuthUtil;
import net.siufung.simple.config.mybatis.id.MybatisIdGenerator;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 陈建峰
 * @since 2022/4/4 6:28 下午
 */
@Configuration
@MapperScan({"net.siufung.simple.*.mapper"})
public class MybatisAutoConfig {

    @Bean
    public MybatisMetaObjectService metaObjectService(){
        return new DefaultMybatisMetaObjectService();
    }

    @Bean
    public IdentifierGenerator identifierGenerator(){
        return new MybatisIdGenerator();
    }

    /**
     * 配置MetaObject 创建人和创建日期
     */
    static class DefaultMybatisMetaObjectService extends AbstractMybatisMetaObjectService {

        @Override
        public String getCurrentUserId() {
            return AuthUtil.getUserId();
        }
    }


}
